using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;
using Orchard.Core.Title.Models;
using Orchard.Data.Migration;
using Orchard.Data;
using Orchard;
using Orchard.ContentManagement;
using System.Data;

namespace Mod.Web.Orchard.Items
{
    public class Migrations : DataMigrationImpl
    {
        public Migrations()
        {
        }

        public int Create()
        {
            SchemaBuilder.CreateTable("iFrameColorBoxWidgetRecord", table => table
                .ContentPartRecord()
                .Column("FullScreen", DbType.Boolean)
                .Column("Link", DbType.String)
                .Column("Text", DbType.String)
                .Column("Height", DbType.String)
                .Column("Width", DbType.String)
            );

            ContentDefinitionManager.AlterPartDefinition("iFrameColorBoxWidgetPart", cfg => cfg
                .WithField("Image", field => field.OfType("MediaPickerField"))
            );

            ContentDefinitionManager.AlterTypeDefinition("iFrameColorBoxWidget", cfg => cfg
                .WithPart("WidgetPart")
                .WithPart("CommonPart")
                .WithPart("iFrameColorBoxWidgetPart")
                
                //.WithField("Description", field => field.OfType("HtmlField"))
                .WithSetting("Stereotype", "Widget"));


            return 1;
        }

        public int UpdateFrom1()
        {
            ContentDefinitionManager.AlterPartDefinition("ColorBoxBigPart", builder => builder
                .Attachable());

            return 2;
        }

        public int UpdateFrom2()
        {
            SchemaBuilder.CreateTable("ColorBoxBigPartRecord",
                    table => table
                        .ContentPartRecord()
                        );

            return 3;
        }

        public int UpdateFrom3()
        {
            SchemaBuilder.CreateTable("iFrameColorBoxPartRecord", table => table
                .ContentPartRecord()
                .Column("FullScreen", DbType.Boolean)
                .Column("Link", DbType.String)
                .Column("Text", DbType.String)
                .Column("Height", DbType.String)
                .Column("Width", DbType.String)
            );

            ContentDefinitionManager.AlterPartDefinition("iFrameColorBoxPart", cfg => cfg
                .WithField("Image", field => field.OfType("MediaPickerField"))
            );

            return 4;
        }

        public int UpdateFrom4()
        {
            ContentDefinitionManager.AlterTypeDefinition("ColorBoxWidget", cfg => cfg
                .WithPart("WidgetPart")
                .WithPart("CommonPart")
                .WithPart("iFrameColorBoxPart")

                //.WithField("Description", field => field.OfType("HtmlField"))
                .WithSetting("Stereotype", "Widget"));

            return 5;
        }

        //    ContentDefinitionManager.AlterPartDefinition("StandardItemPart", cfg => cfg
        //        .WithField("Description", field => field.OfType("HtmlField"))
        //        .WithField("Thumbnail", field => field.OfType("MediaPickerField"))
        //        .WithField("Length", field => field.OfType("TextField"))
        //        .WithField("Type", field => field.OfType("TaxonomyField").WithSetting("FieldIndexing.Included", "True")
        //                                                                   .WithSetting("TaxonomyFieldSettings.TaxonomyId", itemTypeTaxonomy.Id.ToString())
        //                                                                   .WithSetting("TaxonomyFieldSettings.LeavesOnly", "True")
        //                                                                   .WithSetting("TaxonomyFieldSettings.SingleChoice", "True"))
        //        .WithField("Vendor", field => field.OfType("TaxonomyField").WithSetting("FieldIndexing.Included", "True")
        //                                                                   .WithSetting("TaxonomyFieldSettings.TaxonomyId", vendorTaxonomy.Id.ToString())
        //                                                                   .WithSetting("TaxonomyFieldSettings.LeavesOnly", "True")
        //                                                                   .WithSetting("TaxonomyFieldSettings.SingleChoice", "True"))
        //        .WithField("Topic", field => field.OfType("TaxonomyField").WithSetting("FieldIndexing.Included", "True")
        //                                                                   .WithSetting("TaxonomyFieldSettings.TaxonomyId", topicTaxonomy.Id.ToString())
        //                                                                   .WithSetting("TaxonomyFieldSettings.LeavesOnly", "True")
        //                                                                   .WithSetting("TaxonomyFieldSettings.SingleChoice", "True"))
        //    );

            
        //    ContentDefinitionManager.AlterTypeDefinition("DynamicListWidget", cfg => cfg
        //        .WithPart("DynamicListPart")
        //        .WithPart("WidgetPart")
        //        .WithPart("CommonPart")
        //        .WithSetting("Stereotype", "Widget"));

            
        
    }
}